<script>
function expand(id) {
	$j('#maincat-' + id).show();
	$j('#act-' + id).html('<a href="javascript:collapse(' + id +')"><img src="<?=base_url()?>img/backend/minus.gif" /></a>');
}
function collapse(id) {
	$j('#maincat-' + id).hide();
	$j('#act-' + id).html('<a href="javascript:expand(' + id +')"><img src="<?=base_url()?>img/backend/plus.gif" /></a>');
}
function insertoption() {
	var id = $j('#attribute').val();
	if ($j('#attribute-' + id).val() == id) {
		alert('You have already inserted this atttribute');
	} else {
		$j.ajax({
			url: '<?=base_url()?>admin/system/getattributes/',
			type: 'POST',
			data: ({id:id}),
			dataType: "html",
			success: function(html) {
				$j('#optcontent').append(html);
			}
		})
	}
}
function addoption(id,n) {
	var opt = $j('#optval-' + id).val();
	if ($j.trim(opt) != '') {
		$j('#optval-' + id).val('');
		$j('#options-' + id).append('<dl class="five" id="opt-' + id + '-' + n + '"><dt>' + opt + '</dt><dd><a href="javascript:removeoption(' + id + ',' + n + ')"><img src="<?=base_url()?>img/backend/icon-delete-small.png" /></a></dd><input type="hidden" value="' + opt + '" name="options-' + id + '[]" /></dl>');
		$j('#optbutton-' + id).html('<input type="button" class="button rounded" value="&raquo;" onclick="addoption(' + id + ',' + (n+1) + ')" />');
	} else {
		alert('Please enter a valid option');
	}
}
function removeoption(id,n) {
	$j('#opt-' + id + '-' + n).remove();	
}
function removeattr(id) {
	$j('#attr-' + id).remove();
}
function switchall() {
	var cond = $j('#allcat:checked').val();
	if (cond) {  
		$j('[id^=category-]').attr('checked',true);
	} else { 
		$j('[id^=category-]').attr('checked',false);
	}
}
function overwrite(id,parent) {
	var cond = $j('#category-' + id + ':checked').val();
	if (cond) {
		$j('#category-' + parent).attr('checked',true);
	}
}
$j(document).ready(function(){
	
		activestock(0);
	
});
function activestock(n){
	if(n==0){
		$j('#typestock').css({'display':'none'});
		$j('#typestock_normal').css({'display':'block'});
		
	}else{
		$j('#typestock').css({'display':'block'});
		$j('#typestock_normal').css({'display':'none'});
		
	}
}
</script>
    	<div class="left">
        	<h1>Store Management</h1>
            <div class="bar">

            	<div class="text">Manage Products &raquo; Add new Product</div>
            	<div class="cr"></div>
            </div>
            <div class="box">
            	<p>
                	<input type="button" class="button rounded" value="Back to Products List" onclick="history.go(-1)" />
                </p>
            </div>            
            <hr />
            <form id="addProduct" method="post" action="<?=base_url()?>admin/store/addproduct">
            <div class="box bgw">
            	<h3>Basic Details</h3>
                <dl class="two"><dt>Title</dt><dd><input type="text" class="textfield rounded" name="title" /></dd></dl>
                <dl class="two"><dt>Short description</dt><dd><input type="text" class="textfield rounded" name="short_desc" /></dd></dl>
                <dl class="two"><dt>Long description</dt><dd><textarea name="long_desc"></textarea></dd></dl>
                <dl class="three"><dt>Price</dt><dd><input type="text" class="textfield rounded" name="price" /></dd>
                		<dd>Sale price</dd><dd><input type="text" class="textfield rounded" name="sale_price" /></dd></dl>
                <dl class="three"><dt>Trade Price</dt><dd><input type="text" class="textfield rounded" name="price_trade" /></dd>
                		<dd>Sale price</dd><dd><input type="text" class="textfield rounded" name="sale_price_trade" /></dd></dl>
                <dl class="two"><dt>Style number</dt><dd><input type="text" class="textfield rounded" name="style_no" /></dd></dl>
				<dl class="two"><dt>Dimension</dt><dd><input type="text" class="textfield rounded" name="product_dimension" /></dd></dl>
				 <dl class="two"><dt>Multiple Size Stock</dt><dd>NO <input onclick="activestock(0)" type="radio" name="typeproduct" value="no" checked="checked" /> YES <input type="radio" onclick="activestock(1)" name="typeproduct" value="yes" /></dd></dl>		
					
				<div id="typestock">
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size XXXS</div><div class="sizewidth" > <input type="number" class="textfield rounded" name="XXXS" /></div><div class="sizewidth margin-left" >Min XXXS</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_XXXS" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size XXS</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="XXS" /></div><div class="sizewidth margin-left" >Min XXS</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_XXS" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size XS</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="XS" /></div><div class="sizewidth margin-left" >Min XS</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_XS" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size S</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="S" /></div><div class="sizewidth margin-left" >Min S</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_S" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size M</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="M" /></div><div class="sizewidth margin-left" >Min M</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_M" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size L</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="L" /></div><div class="sizewidth margin-left" >Min L</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_L" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="XL" /></div><div class="sizewidth margin-left" >Min XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_XL" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size XXL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="XXL" /></div><div class="sizewidth margin-left" >Min XXL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_XXL" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 3XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="3XL" /></div><div class="sizewidth margin-left" >Min 3XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_3XL" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 4XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="4XL" /></div><div class="sizewidth margin-left" >Min 4XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_4XL" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 5XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="5XL" /></div><div class="sizewidth margin-left" >Min 5XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_5XL" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 6XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="6XL" /></div><div class="sizewidth margin-left" >Min 6XL</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_6XL" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 6</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="6" /></div><div class="sizewidth margin-left" >Min 6</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_6" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 8</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="8" /></div><div class="sizewidth margin-left" >Min 8</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_8" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 10</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="10" /></div><div class="sizewidth margin-left" >Min 10</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_10" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 12</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="12" /></div><div class="sizewidth margin-left" >Min 12</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_12" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 14</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="14" /></div><div class="sizewidth margin-left" >Min 14</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_14" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 16</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="16" /></div><div class="sizewidth margin-left" >Min 16</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_16" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 18</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="18" /></div><div class="sizewidth margin-left" >Min 18</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_18" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 20</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="20" /></div><div class="sizewidth margin-left" >Min 20</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_20" /></div></dd></dl>
				<dl class="six"><dt>&nbsp;</dt><dd><div class="sizewidth" >Size 22</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="22" /></div><div class="sizewidth margin-left" >Min 22</div><div class="sizewidth" ><input type="number" class="textfield rounded" name="min_22" /></div></dd></dl>
				</div> <!-- end of typestock -->
               <div id="typestock_normal">		
				<dl class="two"><dt>Stock</dt><dd><input type="text" class="textfield rounded" name="product_stock" value="" /></dd></dl>
				<dl class="two"><dt>Min_Stock</dt><dd><input type="text" class="textfield rounded" name="min_product_stock" value="10" /></dd></dl>
               </div>
                <dl></dl>
            </div>
            <hr />
            <div class="box">
            	<h3>Display product in the categories</h3>
                <p class="desc">Select a primary category on the left to display it's sub caregories. You can select multiple categoreis</p>
                <div id="catwrap">
                	<div class="level1"><input type="checkbox" onchange="switchall()" id="allcat" /> All categories</div>
                    <?php foreach($main as $maincat) { ?>
                    <div class="level2"><input type="checkbox" name="categories[]" value="<?=$maincat['id']?>" id="category-<?=$maincat['id']?>" class="cat-check" /> <span id="act-<?=$maincat['id']?>"><a href="javascript:expand(<?=$maincat['id']?>)"><img src="<?=base_url()?>img/backend/plus.gif" /></a></span> <?=$maincat['title']?></div>
                    <div id="maincat-<?=$maincat['id']?>" class="hidden">
                    <?php $sub = $this->Category_model->get($maincat['id']);
						foreach($sub as $subcat) { ?>
						<div class="level3"><input type="checkbox" name="categories[]" value="<?=$subcat['id']?>" id="category-<?=$subcat['id']?>" class="cat-check" onchange="overwrite(<?=$subcat['id']?>,<?=$maincat['id']?>)" /> <?=$subcat['title']?></div>
						<?php } ?>
                    </div>
					<?php } ?>                    
                </div>                               
            </div>
            <hr />
            <div class="box bgw">
            	<h3>Shipping</h3>
                <dl class="four"><dt>Product weight</dt><dd><input type="text" class="textfield rounded" name="weight" id="weight" /></dd><dd>Please enter the weight in kilo in format 00.00</dd></dl>                
                <dl></dl>
            </div>
            <hr />
            <div class="box">
            	<h3>Product attributes</h3>
                <dl class="four"><dt>Select option</dt><dd>
                	<select id="attribute">
                    	<?php foreach($attributes as $attr) { ?>
                        <option value="<?=$attr['id']?>"><?=$attr['name']?></option>
                        <?php } ?>
                    </select>
                </dd><dd><input type="button" class="button rounded" value="Insert" onclick="insertoption()" /></dd></dl>
                <dl></dl>
                <div id="optcontent">                	
                </div>
            </div>
            <hr />
            <div class="box bgw"><input type="submit" class="button rounded" value="Create Product" /></div>
            </form>
        </div>
        
